sinclude ../scripts/xbuild/env.mk

ARCH		?= x86

ifeq ($(ARCH),x86) # x86

ifeq ($(LLVM),)
CC			:= $(CROSS_COMPILE)gcc -m32
AS			:= $(CROSS_COMPILE)gcc -m32
LD			:= $(CROSS_COMPILE)ld -m elf_i386
endif

MCFLAGS		:= -march=i386
TRIPLE_ARCH	:= i386
else ifeq ($(ARCH),riscv64) # riscv64

MCFLAGS		:= -march=rv64imafdc -mabi=lp64d -mcmodel=medany -DNX_CPU_64BIT
TRIPLE_ARCH	:= riscv64

else ifeq ($(ARCH),aarch64) # aarch64

MCFLAGS		:= -march=armv8-a -mtune=cortex-a72  -DNX_CPU_64BIT
TRIPLE_ARCH	:= aarch64
else
$(error unsupported arch!)
endif

ifneq ($(LLVM),)
MCFLAGS		+= --target=$(TRIPLE_ARCH)-unknown-unknown-elf
endif

X_CFLAGS	:= $(MCFLAGS) -fno-builtin -fno-stack-protector
X_CFLAGS	+= -nostdlib -nostdinc -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99

X_ACFLAGS	+= $(MCFLAGS) -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99

X_LDFLAGS 	:= -no-pie -n
X_LDFLAGS 	+= -nostdlib

X_INCDIRS	:= include

SRC			:= arch/$(ARCH)/
SRC			+= crt/
SRC			+= process/
SRC			+= debug/
SRC			+= utils/
SRC			+= fs/
SRC			+= ipc/
SRC			+= mman/
SRC			+= time/
SRC			+= device/

TARGET_TYPE	:= static
NAME		:= nxos
